package com.clp.protocol.iec104.apdu.asdu.info_obj.info_elem.file_transfer.dt_file;

import com.clp.protocol.core.common.frame.InitializableFrameClip;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
 * 传输文件的属性（备用）
 */
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class DTFileProperty implements InitializableFrameClip<DTFileProperty> {
    private byte propertyByte;

    @Override
    public DTFileProperty initBy(ByteBuf buf) {
        this.propertyByte = buf.readByte();;
        return this;
    }

    @Override
    public boolean isValid() {
        return true;
    }

    @Override
    public void writeTo(ByteBuf buf) {
        buf.writeByte(propertyByte);
    }

    @Override
    public String toString() {
        // TODO 暂时这样
        return null;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        DTFileProperty that = (DTFileProperty) o;
        return propertyByte == that.propertyByte;
    }

    @Override
    public int hashCode() {
        return Objects.hash(propertyByte);
    }
}
